package PolladminFunc;

import java.sql.ResultSet;
import java.util.ArrayList;

import PollcreatorFunc.Pollcreator;

import utils.DBConn;

public class PollcreatorDAO extends DBConn {

	private ResultSet rs;
	
	public void add(Pollcreator pct){
		try{
			super.getConnection();
			String sql="INSERT INTO PollUser(Username,Password,Email,Accessibility,FName,LName)VALUES(?,?,?,?,?,?)";
			ps=conn.prepareStatement(sql);
			ps.setString(1, pct.getUsername());
			ps.setString(2, pct.getPassword());
			ps.setString(3, pct.getEmail());
			ps.setInt(4, pct.getAccessibility());
			ps.setString(5, pct.getFname());
			ps.setString(6,pct.getLname());
			ps.executeUpdate();
		}catch(Exception e){e.printStackTrace();}
	}
	
	public ArrayList<Pollcreator> show(){
		ArrayList<Pollcreator> pctList = new ArrayList<Pollcreator>();
		super.getConnection();
		String sql="SELECT Username,Email,FName,LName,Createtime FROM PollUser WHERE Accessibility = 3";
		try{
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery(sql);
			Pollcreator pct=null;
			while(rs.next()){
				pct=new Pollcreator();
				pct.setUsername(rs.getString("Username"));
				pct.setEmail(rs.getString("Email"));
				pct.setFname(rs.getString("FName"));
				pct.setLname(rs.getString("LName"));
				pct.setCreatetime(rs.getDate("CreateTime"));
				pctList.add(pct);
			}
		}catch(Exception e){e.printStackTrace();}
		return pctList;
	}
	
	public void delete(Pollcreator pct){
		try{
			super.getConnection();
			String sql="";
			ps=conn.prepareStatement(sql);
			ps.executeUpdate();
		}catch(Exception e){e.printStackTrace();}
	}
	
	public void update(Pollcreator pct){
		try{
			super.getConnection();
			String sql="";
			ps=conn.prepareStatement(sql);
			ps.executeUpdate();
		}catch(Exception e){e.printStackTrace();}
	}
}
